package common

import (
	"strconv"
	"strings"
)

// CompareVersions - 自定义版本号比较函数
func CompareVersions(verA, verB string) int {
	partsA := strings.Split(verA, ".")
	partsB := strings.Split(verB, ".")

	for i := 0; i < len(partsA) || i < len(partsB); i++ {
		var numA, numB int
		if i < len(partsA) {
			numA, _ = strconv.Atoi(partsA[i])
		}
		if i < len(partsB) {
			numB, _ = strconv.Atoi(partsB[i])
		}
		if numA > numB {
			return 1
		} else if numA < numB {
			return -1
		}
	}
	return 0
}
